package com.zhk.entry.scoket;


import com.zhk.entry.util.CThreadConn;

import java.io.IOException;
import java.net.Socket;

/**
 * 服务器端
 */
public class ServerSocket {
    public static void main(String[] args) {

        try {
            //1、创建一个服务器端Socket,即ServerSocket,指定绑定的端口，并监听此端口
            java.net.ServerSocket serverSocket = new java.net.ServerSocket(8889);
            //2、调用accept()方法开始监听，等待客户端的连接
            System.out.println("*****服务器即将启动，等待客户端的连接****");
//            Socket socket = serverSocket.accept();
            Socket socket = null;
            int count = 0;
            while(true)
            {
                socket = serverSocket.accept();
//                ServerThread serverThread = new ServerThread(socket,new CThreadConn(),new UserMapper(new BaseDao()));
                ServerThread serverThread = new ServerThread(socket,new CThreadConn(),null);

                serverThread.start();
                count++;
                socket.getInetAddress();//ip地址
                System.out.println("客户端的数量："+count);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

